import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IMoneyStrategy } from "../IMoneyStrategy";

export interface IStepMultipleOption {
    multiple: number;
    baseMoney: number;
    stepLimitMoney: number;
    stepMoney: number;
}
export class StepMultipleMoneyStrategy implements IMoneyStrategy {
    option: IStepMultipleOption;
    recmV: EnumBjlResult = EnumBjlResult.U;
    recmMoney: number = 0;
    stepLimitMoney: number = 320;
    stepMoney: number = 50;
    constructor(name: string, option?: IStepMultipleOption | null) {
        this.strategyName = name;
        if (option) {
            this.option = option;
        }
        else {
            this.option = {
                multiple: 2,
                baseMoney: 10,
                stepLimitMoney: 320,
                stepMoney: 50
            };
        }
        this.resetStrategy();
    }
    showMoney(): [EnumBjlResult, number] {
        return [this.recmV, this.recmMoney];
    }
    resetRecm(): void {
        this.resetStrategy();
    }
    resetStrategy(): void {
        this.recmV = EnumBjlResult.U;
        this.recmMoney = 0;
        this.stepLimitMoney = this.option.stepLimitMoney;
        this.stepMoney = this.option.stepMoney;
    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let recmV = roundInfo.userRecm;
        let recmMoney = this.recmMoney;

        if (recmMoney > this.stepLimitMoney) {
            if (recmInfo.summaryInfo.prevResult == EnumBetResult.Success) {
                recmMoney = recmMoney - this.stepMoney;
            }
            else if (recmInfo.summaryInfo.prevResult == EnumBetResult.Fail) {
                recmMoney = recmMoney + this.stepMoney;
            }
        }
        else if (recmMoney == this.stepLimitMoney) {
            if (recmInfo.summaryInfo.prevResult == EnumBetResult.Success) {
                recmMoney = recmMoney / this.option.multiple;
                recmInfo.roundSummaryInfo.resetSummaryInfo();
            }
            else if (recmInfo.summaryInfo.prevResult == EnumBetResult.Fail) {
                recmMoney = recmMoney + 50;
            }
        }
        else {

            if (recmInfo.roundSummaryInfo.lfail == 2) {
                recmMoney = recmMoney * this.option.multiple;
                recmInfo.roundSummaryInfo.resetSummaryInfo();
            }
            else if (recmInfo.roundSummaryInfo.winCount == recmInfo.roundSummaryInfo.failCount) {
                recmInfo.roundSummaryInfo.resetSummaryInfo();
            }
            else if (recmInfo.roundSummaryInfo.lwin == 1) {
                recmMoney = recmMoney / this.option.multiple;
                recmInfo.roundSummaryInfo.resetSummaryInfo();
            }


        }

        if (recmMoney < this.option.baseMoney) {
            recmMoney = this.option.baseMoney;
        }

        this.recmV = recmV;
        this.recmMoney = recmMoney;
        return [recmV, recmMoney];
    }
    strategyName: string;
    debugCompoenent: string = "";
    copyValue(valueObj: any): void {
        let obj = valueObj as StepMultipleMoneyStrategy;
        if (obj) {
            //复制
            this.recmV = obj.recmV;
            this.recmMoney = obj.recmMoney;
        }
    }

}
